﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace CMS6Tools.Management
{
    public partial class MainForm : Form
    {
        #region Ctor
        public MainForm()
        {
            InitializeComponent();
        }
        #endregion

        #region Load
        private void MainForm_Load(object sender, EventArgs e)
        {

        }
        #endregion

        #region events
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void codeChangeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!TFSAuthenticate())
                return;

            var codeChangeTrackForm = new CodeChangeTrackForm();
            codeChangeTrackForm.CloseButton = true;
            codeChangeTrackForm.Show(MainDockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document);
        }
        #endregion

        #region
        private void kPIToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!TFSAuthenticate())
                return;

            var kpiForm = new KPIForm();
            kpiForm.CloseButton = true;
            kpiForm.Show(MainDockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document);
        }
        #endregion

        #region About
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Welcome to use CMS6 Management Tool.");
        }
        #endregion

        #region Authetication
        private bool TFSAuthenticate()
        {
            if (!Util.AutoAuthenticate())
            {
                var tfsAuthenticationForm = new TFSAuthenticationForm();
                tfsAuthenticationForm.StartPosition = FormStartPosition.CenterParent;
                var dialogResult = tfsAuthenticationForm.ShowDialog();
                var result = Util.AuthenticatedTfsTeamProjectCollection != null;
                if (!result)
                    MessageBox.Show("Sorry, Login Failed.");

                return result;
            }
            return true;
        }
        #endregion


        #region Menu
        private void releasePackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!TFSAuthenticate())
                return;

            var releasePackageForm = new ReleasePackageForm();
            releasePackageForm.CloseButton = true;
            releasePackageForm.Show(MainDockPanel, DockState.Document);
        }
        #endregion

        private void timeMatrixToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!TFSAuthenticate())
                return;

            var timeMatrixForm = new TimeMatrixForm();
            timeMatrixForm.CloseButton = true;
            timeMatrixForm.Show(MainDockPanel, DockState.Document);

        }

        private void featureUsageMatrixToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var featureUsageMatrixForm = new FeatureUsageMatrixForm();
            featureUsageMatrixForm.CloseButton = true;
            featureUsageMatrixForm.Show(MainDockPanel, DockState.Document);

        }

        private void dailyToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (!TFSAuthenticate())
                return;

            var dailyTrackFrom = new DailyTrackingForm();
            dailyTrackFrom.CloseButton = true;
            dailyTrackFrom.Show(MainDockPanel, DockState.Document);
        }

        private void cMSHosting36ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var cMSHostingForm = new CMSHostingForm();
            cMSHostingForm.CloseButton = true;
            cMSHostingForm.Show(MainDockPanel, DockState.Document);

        }
    }
}
